package practice.game.plane.ui;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import practice.game.plane.bean.Consts;
import practice.game.plane.bean.PlaneInfo;

@SuppressWarnings("serial")
public class LayoutSetPanel extends JPanel {
	private LayoutSetSinglePanel[] settings;

	public LayoutSetPanel() {
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		settings = new LayoutSetSinglePanel[] {
				new LayoutSetSinglePanel(Consts.PLANE_COLORS[0]),
				new LayoutSetSinglePanel(Consts.PLANE_COLORS[1]),
				new LayoutSetSinglePanel(Consts.PLANE_COLORS[2]),
				new LayoutSetSinglePanel(Consts.PLANE_COLORS[3]),
				new LayoutSetSinglePanel(Consts.PLANE_COLORS[4]) };

		for (LayoutSetSinglePanel layoutSetSinglePanel : settings) {
			add(layoutSetSinglePanel);
		}
	}

	public PlaneInfo[] getPlanes() {
		PlaneInfo[] planeInfos = new PlaneInfo[settings.length];
		for (int i = 0; i < settings.length; i++) {
			planeInfos[i] = settings[i].getPlanInfo();
		}
		return planeInfos;
	}

	public void setPlanes(PlaneInfo[] planes) {
		if (planes.length > settings.length) {
			return;
		}
		for (int i = 0; i < Math.min(planes.length, settings.length); i++) {
			settings[i].setPlanInfo(planes[i]);
		}
	}

}
